//
//  HealthViewController.m
//  parent
//
//  Created by yanzhen on 15/7/23.
//  Copyright (c) 2015年 ci123. All rights reserved.
//

#import "HealthViewController.h"
#import "Masonry.h"
#import "HealthAddViewController.h"
#import "TBXML+HTTP.h"
#import "Config.h"
#import "AFAppClient.h"

@interface HealthViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property NSMutableArray *nos;
@property NSDate  *selected_date;
@property (weak, nonatomic) IBOutlet UIButton *dateFilter;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;

@property UIPickerView *pickerView;
@property UITextField *textField1;

@property (weak, nonatomic) IBOutlet UIScrollView *scrollview;

@property (weak, nonatomic) IBOutlet UIView *containerView;
@property (strong, nonatomic) TBXML *tbxml;
@property (weak, nonatomic) IBOutlet UILabel *height1;
@property (weak, nonatomic) IBOutlet UILabel *height_ref;
@property (weak, nonatomic) IBOutlet UILabel *weight;
@property (weak, nonatomic) IBOutlet UILabel *weight_ref;
@property (weak, nonatomic) IBOutlet UILabel *bbf_fat;
@property (weak, nonatomic) IBOutlet UILabel *bbf_fat_ref;//无参考
@property (weak, nonatomic) IBOutlet UILabel *bbf_bmi;
@property (weak, nonatomic) IBOutlet UILabel *bbf_bmi_ref;//18.5至24.99为正常
@property (weak, nonatomic) IBOutlet UILabel *bbf_BasalMetaRate;
@property (weak, nonatomic) IBOutlet UILabel *bbf_BasalMetaRate_ref;//无参考
@property (weak, nonatomic) IBOutlet UILabel *tmp;
@property (weak, nonatomic) IBOutlet UILabel *tmp_ref;//35.8℃~37.8℃
@property (weak, nonatomic) IBOutlet UILabel *bg;
@property (weak, nonatomic) IBOutlet UILabel *bg_ref;//3.9~6.1
@property (weak, nonatomic) IBOutlet UILabel *bp_sbp;
@property (weak, nonatomic) IBOutlet UILabel *bp_sbp_ref;//90~139
@property (weak, nonatomic) IBOutlet UILabel *bp_dbp;
@property (weak, nonatomic) IBOutlet UILabel *bp_dbp_ref;//60~89
@property (weak, nonatomic) IBOutlet UILabel *po_spo2;
@property (weak, nonatomic) IBOutlet UILabel *po_spo2_ref;//94~100
@property (weak, nonatomic) IBOutlet UILabel *ecg_hr;
@property (weak, nonatomic) IBOutlet UILabel *ecg_hr_ref;//60~100
@property (weak, nonatomic) IBOutlet UILabel *pf_fvc;
@property (weak, nonatomic) IBOutlet UILabel *pf_fvc_ref;//无
@property (weak, nonatomic) IBOutlet UILabel *pf_fev1;
@property (weak, nonatomic) IBOutlet UILabel *pf_fev1_ref;//无
@property (weak, nonatomic) IBOutlet UILabel *pf_pef;
@property (weak, nonatomic) IBOutlet UILabel *pf_pef_ref;//无
/*
@property (weak, nonatomic) IBOutlet UILabel *pf_fef25;
@property (weak, nonatomic) IBOutlet UILabel *pf_fef25_ref;//无
@property (weak, nonatomic) IBOutlet UILabel *pf_fef75;
@property (weak, nonatomic) IBOutlet UILabel *pf_fef75_ref;//无
@property (weak, nonatomic) IBOutlet UILabel *pf_fef2575;
@property (weak, nonatomic) IBOutlet UILabel *pf_fef2575_ref;//无
 */
@property (weak, nonatomic) IBOutlet UILabel *pw_uro;
@property (weak, nonatomic) IBOutlet UILabel *pw_uro_ref;//norml
@property (weak, nonatomic) IBOutlet UILabel *pw_pro;
@property (weak, nonatomic) IBOutlet UILabel *pw_pro_ref;//-或+-
@property (weak, nonatomic) IBOutlet UILabel *pw_glu;
@property (weak, nonatomic) IBOutlet UILabel *pw_glu_ref;//值-为正常
@property (weak, nonatomic) IBOutlet UILabel *pw_ket;
@property (weak, nonatomic) IBOutlet UILabel *pw_ket_ref;//值-为正常
@property (weak, nonatomic) IBOutlet UILabel *pw_bil;
@property (weak, nonatomic) IBOutlet UILabel *pw_bil_ref;//值-为正常
@property (weak, nonatomic) IBOutlet UILabel *pw_bld;
@property (weak, nonatomic) IBOutlet UILabel *pw_bld_ref;//值-为正常
@property (weak, nonatomic) IBOutlet UILabel *pw_vc;
@property (weak, nonatomic) IBOutlet UILabel *pw_vc_ref;//值-为正常
@property (weak, nonatomic) IBOutlet UILabel *pw_sg;
@property (weak, nonatomic) IBOutlet UILabel *pw_sg_ref;//值1.005~1.030为正常
@property (weak, nonatomic) IBOutlet UILabel *pw_leu;
@property (weak, nonatomic) IBOutlet UILabel *pw_leu_ref;//值-为正常
@property (weak, nonatomic) IBOutlet UILabel *pw_nit;
@property (weak, nonatomic) IBOutlet UILabel *pw_nit_ref;//值-为正常
@property (weak, nonatomic) IBOutlet UILabel *pw_ph;
@property (weak, nonatomic) IBOutlet UILabel *pw_ph_ref;//无

@property UIDatePicker *datePicker;
@property UITextField *textField;
@end


@implementation HealthViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title=@"健康管家";
    UIBarButtonItem *rightItem =[[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"加人"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(rightItemClick:)];
    self.navigationItem.rightBarButtonItem = rightItem;
    [self CustomBackButton];
    self.dateFilter.layer.borderColor = [UIColorMake(101, 101, 101) CGColor];
    self.dateFilter.layer.borderWidth = .25;
    self.dateFilter.layer.cornerRadius=2.0;

    //[self initContent];
    
   // [self getXMLDATA:@"342530198606130814"];
    [self getAllNos];
    
    _datePicker = [[UIDatePicker alloc]init];
    [_datePicker setMaximumDate:[NSDate date]];
    [_datePicker setMinimumDate:[NSDate dateWithTimeIntervalSinceNow:-1 * 3600* 24 * 365]];
    /*
     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
     
     [dateFormatter setDateFormat: @"yyyy-MM-dd "];
     NSDate *destDate= [dateFormatter dateFromString:dateString];
     */
    [_datePicker setDate:[NSDate dateWithTimeIntervalSinceNow:-1 * 3600* 24 * 11]];
    _datePicker.datePickerMode = UIDatePickerModeDate;
    [_datePicker addTarget:self action:@selector(changeDate:) forControlEvents:UIControlEventValueChanged];
    _textField = [[UITextField alloc]initWithFrame:CGRectMake(0, 260, 0, 0)];
    _textField.placeholder=@"";
    [_textField setInputView:_datePicker];
    [self.view addSubview:_textField];
    
    
    _pickerView = [[UIPickerView alloc] init];
    
    [_pickerView sizeToFit];
    _pickerView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    _pickerView.delegate = self;
    _pickerView.dataSource = self;
    _pickerView.showsSelectionIndicator = YES;
    
    _textField1 = [[UITextField alloc]initWithFrame:CGRectMake(0, 190, 0, 0)];
    [_textField1 setInputView:_pickerView];
    [self.view addSubview:_textField1];

    _bbf_bmi_ref.text = @"18.5~24.99";
    _tmp_ref.text = @"35.8℃~37.8℃";
    _bg_ref.text = @"3.9~6.1";
    _bp_sbp_ref.text = @"90~139";
    _bp_dbp_ref.text = @"60~89";
    _po_spo2_ref.text=@"94~100";
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData:) name:kAddHealth object:nil];
}

-(void)reloadData:(id)sender
{
    [self getAllNos];
}

-(void)changeDate:(UIDatePicker *)picker
{
    NSDateFormatter *format = [[NSDateFormatter alloc]init];
    [format setDateFormat:@"yyyy.MM.dd"];
    
    //_birthday.text = [format stringFromDate:picker.date];
    
    NSString *birth_str = [format stringFromDate:picker.date];
    _dateLabel.text = [NSString stringWithFormat:@"体检日期:%@",birth_str];
}


-(void)getAllNos
{
    [self showHud:@"正在加载..." isDim:YES];
    [[AFAppClient sharedManager]getWithURL:[NSString stringWithFormat:@"%@%@",SERVER_URL_NEW,kGetHealthNos] withParameters:@{@"uid":@([[Config Instance]getUID])} success:^(NSDictionary *responseObject) {
        
        if([[responseObject objectForKey:@"code"]integerValue]==1){
           [self hideHud2];
            NSArray *result = [responseObject objectForKey:@"result"];
            _nos = [[NSMutableArray alloc]initWithArray:result];
            NSDictionary *info = [_nos objectAtIndex:0];
            NSString *number = [info objectForKey:@"number"];
            _nameLabel.text = [NSString stringWithFormat:@"姓名：%@",[info objectForKey:@"name"]];
            [self getXMLDATA:number];
            [_pickerView reloadAllComponents];
        }else {
            [self showHudComplete:@"请添加成员" success:NO];
            
        }
    } failure:^(NSError *error) {
        [self showHudComplete:@"网络连接失败" success:NO];
    }];
}


-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}
-(void)initContent
{
    UIView *view1 = [[UIView alloc]init];
    [view1 setBackgroundColor:UIColorMake(0, 192, 189)];
    [_containerView addSubview:view1];
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@(0));
        make.right.mas_equalTo(@(-0));
        make.top.mas_equalTo(@(0));
        make.height.mas_equalTo(@(40));
    }];
    UILabel *label1 = [UILabel new];
    [label1 setTextColor:[UIColor whiteColor]];
    [label1 setFont:[UIFont systemFontOfSize:20.0]];
    [label1 setText:@"姓名:刘德华"];
    [view1 addSubview:label1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(20));
        make.centerY.equalTo(view1.mas_centerY);
        make.width.equalTo(@(150));
        make.height.equalTo(@(20));
    }];
    UILabel *label2 = [UILabel new];
    [label2 setTextColor:[UIColor whiteColor]];
    [label2 setFont:[UIFont systemFontOfSize:20.0]];
    [label2 setText:@"体检日期:2015-7-20"];
    [view1 addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-20));
        make.centerY.equalTo(view1.mas_centerY);
        make.width.equalTo(@(195));
        make.height.equalTo(@(20));
    }];
    
    UIView *view2 = [[UIView alloc]init];
    [view2 setBackgroundColor:UIColorMake(240, 240, 240)];
    [_containerView addSubview:view2];
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@(0));
        make.right.mas_equalTo(@(-0));
        make.top.mas_equalTo(view1.mas_bottom).offset(0);
        make.height.mas_equalTo(@(40));
    }];
    UILabel *label3 = [UILabel new];
    [label3 setTextColor:UIColorMake(0, 192, 189)];
    [label3 setFont:[UIFont systemFontOfSize:20.0]];
    [label3 setText:@"体检项"];
    [view2 addSubview:label3];
    [label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(5));
        make.centerY.equalTo(view2.mas_centerY);
        make.width.equalTo(@(60));
        make.height.equalTo(@(20));
    }];
    UILabel *label4 = [UILabel new];
    [label4 setTextColor:UIColorMake(0, 192, 189)];
    [label4 setFont:[UIFont systemFontOfSize:10.0]];
    [label4 setText:@"(reference value)"];
    [view2 addSubview:label4];
    [label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(label3.mas_right).offset(3);
        make.centerY.equalTo(view2.mas_centerY);
        make.width.equalTo(@(80));
        make.height.equalTo(@(20));
    }];
    UILabel *label6 = [UILabel new];
    [label6 setTextColor:UIColorMake(0, 192, 189)];
    [label6 setFont:[UIFont systemFontOfSize:10.0]];
    [label6 setText:@"(reference value)"];
    [view2 addSubview:label6];
    [label6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-10));
        make.centerY.equalTo(view2.mas_centerY);
        make.width.equalTo(@(80));
        make.height.equalTo(@(20));
    }];
    UILabel *label5 = [UILabel new];
    [label5 setTextColor:UIColorMake(0, 192, 189)];
    [label5 setFont:[UIFont systemFontOfSize:20.0]];
    [label5 setText:@"参考值"];
    [view2 addSubview:label5];
    [label5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(label6.mas_left).offset(-5);
        make.centerY.equalTo(view2.mas_centerY);
        make.width.equalTo(@(60));
        make.height.equalTo(@(20));
    }];
    
    //身高
    UIView *view3 = [[UIView alloc]init];
    [view3 setBackgroundColor:UIColorMake(255, 255, 255)];
    [_containerView addSubview:view3];
    [view3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@(0));
        make.right.mas_equalTo(@(-0));
        make.top.mas_equalTo(view2.mas_bottom).offset(0);
        make.height.mas_equalTo(@(40));
    }];
    UILabel *label7 = [UILabel new];
    [label7 setTextColor:UIColorMake(80, 80, 80)];
    [label7 setFont:[UIFont systemFontOfSize:20.0]];
    NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc ]initWithString:@"身高(cm)"];
    [attrStr setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.0]
                             } range:NSMakeRange(2, 4)];
    [label7 setAttributedText:attrStr];
    [view3 addSubview:label7];
    [label7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(5));
        make.centerY.equalTo(view3.mas_centerY);
        make.width.equalTo(@(60));
        make.height.equalTo(@(20));
    }];
    
    _height1 = [UILabel new];
    [_height1 setTextColor:UIColorMake(80, 80, 80)];
    [_height1 setFont:[UIFont systemFontOfSize:20.0]];
    [view3 addSubview:_height1];
    [_height1 setText:@"--"];
    [_height1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(view3.center);
        make.width.equalTo(@(60));
        make.height.equalTo(@(20));
    }];
    
    _height_ref = [UILabel new];
    [_height_ref setTextColor:UIColorMake(80, 80, 80)];
    [_height_ref setFont:[UIFont systemFontOfSize:20.0]];
    [view3 addSubview:_height_ref];
    [_height_ref setText:@"无"];
    [_height_ref mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-10));
        make.width.equalTo(@(40));
        make.height.equalTo(@(20));
        make.centerY.equalTo(view3.mas_centerY);
    }];
    
    //体重
    UIView *view4 = [[UIView alloc]init];
    [view4 setBackgroundColor:UIColorMake(239, 239, 239)];
    [_containerView addSubview:view4];
    [view4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@(0));
        make.right.mas_equalTo(@(-0));
        make.top.mas_equalTo(view3.mas_bottom).offset(0);
        make.height.mas_equalTo(@(40));
    }];
    UILabel *label8 = [UILabel new];
    [label8 setTextColor:UIColorMake(80, 80, 80)];
    [label8 setFont:[UIFont systemFontOfSize:20.0]];
    NSMutableAttributedString* attrStr2 = [[NSMutableAttributedString alloc ]initWithString:@"体重(cm)"];
    [attrStr2 setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.0]
                             } range:NSMakeRange(2, 4)];
    [label8 setAttributedText:attrStr2];
    [view4 addSubview:label8];
    [label8 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(5));
        make.centerY.equalTo(view4.mas_centerY);
        make.width.equalTo(@(60));
        make.height.equalTo(@(20));
    }];
    
    _weight = [UILabel new];
    [_weight setTextColor:UIColorMake(80, 80, 80)];
    [_weight setFont:[UIFont systemFontOfSize:20.0]];
    [view4 addSubview:_weight];
    [_weight setText:@"--"];
    [_weight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(view4.center);
        make.width.equalTo(@(60));
        make.height.equalTo(@(20));
    }];
    
    _weight_ref = [UILabel new];
    [_weight_ref setTextColor:UIColorMake(80, 80, 80)];
    [_weight_ref setFont:[UIFont systemFontOfSize:20.0]];
    [view4 addSubview:_weight_ref];
    [_weight_ref setText:@"无"];
    [_weight_ref mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-10));
        make.width.equalTo(@(40));
        make.height.equalTo(@(20));
        make.centerY.equalTo(view4.mas_centerY);
    }];
    
    //体温
    UIView *view5 = [[UIView alloc]init];
    [view5 setBackgroundColor:UIColorMake(255, 255, 255)];
    [_containerView addSubview:view5];
    [view5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@(0));
        make.right.mas_equalTo(@(-0));
        make.top.mas_equalTo(view4.mas_bottom).offset(0);
        make.height.mas_equalTo(@(40));
    }];
    UILabel *label9 = [UILabel new];
    [label9 setTextColor:UIColorMake(80, 80, 80)];
    [label9 setFont:[UIFont systemFontOfSize:20.0]];
    NSMutableAttributedString* attrStr3 = [[NSMutableAttributedString alloc ]initWithString:@"体温(℃)"];
    [attrStr3 setAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.0]
                              } range:NSMakeRange(2, 3)];
    [label9 setAttributedText:attrStr3];
    [view5 addSubview:label9];
    [label9 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(5));
        make.centerY.equalTo(view5.mas_centerY);
        make.width.equalTo(@(60));
        make.height.equalTo(@(20));
    }];
    
    _tmp = [UILabel new];
    [_tmp setTextColor:UIColorMake(80, 80, 80)];
    [_tmp setFont:[UIFont systemFontOfSize:20.0]];
    [view5 addSubview:_tmp];
    [_tmp setText:@"--"];
    [_tmp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(view5.center);
        make.width.equalTo(@(60));
        make.height.equalTo(@(20));
    }];
    
    _tmp_ref = [UILabel new];
    [_tmp_ref setTextColor:UIColorMake(80, 80, 80)];
    [_tmp_ref setFont:[UIFont systemFontOfSize:16.0]];
    _tmp_ref.textAlignment = NSTextAlignmentRight;
    [view5 addSubview:_tmp_ref];
    [_tmp_ref setText:@"35.8℃~37.8℃"];
    [_tmp_ref mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-10));
        make.width.equalTo(@(60));
        make.height.equalTo(@(20));
        make.centerY.equalTo(view5.mas_centerY);
    }];

    
//    [self getXMLDATA:@"342530198606130814"];
    
}

-(void)getXMLDATA:(NSString *)peopleNo
{
    //http://www.hanncloud.com/api.asp?personid=342530198606130814
    _tbxml = [[TBXML alloc]initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?personid=%@",GET_HEALTH_URL,peopleNo]] success:^(TBXML *tbxml) {
        TBXMLElement *root = tbxml.rootXMLElement;
        TBXMLElement *series = [TBXML childElementNamed:@"series" parentElement:root];
        //身高表
        TBXMLElement *he = [TBXML childElementNamed:@"he" parentElement:series];
        NSString *text = [TBXML textForElement:he];
        if(text && [text isEqualToString:@"false"]){
            
        }else{
            TBXMLElement *record0 = [TBXML childElementNamed:@"record" parentElement:he ];
            TBXMLElement *height = [TBXML childElementNamed:@"value" parentElement:record0];
            NSString *str_height = [TBXML textForElement:height];
//            _height.text = [NSString stringWithFormat:@"%@==",str_height];
            
            TBXMLElement *checkdate = [TBXML nextSiblingNamed:@"value" searchFromElement:height];
            NSString *str_checkdate = [TBXML textForElement:checkdate];

            dispatch_async(dispatch_get_main_queue(), ^{
                [_height1 setText:str_height];
                NSDateFormatter *format =  [[NSDateFormatter alloc]init];
                [format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                
                NSDate *dateN = [format dateFromString:str_checkdate];
                [format setDateFormat:@"yyyy.MM.dd"];
                [_dateLabel setText:[NSString stringWithFormat:@"体检日期:%@",[format stringFromDate:dateN] ]];
            });
            
        }
        //体重表
        TBXMLElement *we = [TBXML childElementNamed:@"we" parentElement:series];
        NSString *text1 = [TBXML textForElement:we];
        if(text1 && [text1 isEqualToString:@"false"]){
            
        }else{
            TBXMLElement *record0 = [TBXML childElementNamed:@"record" parentElement:we ];
            TBXMLElement *weight = [TBXML childElementNamed:@"value" parentElement:record0];
            NSString *str_weight = [TBXML textForElement:weight];
            dispatch_async(dispatch_get_main_queue(), ^{
                [_weight setText:str_weight];
            });
        }
        
        //体脂表
        TBXMLElement *bbf = [TBXML childElementNamed:@"bbf" parentElement:series];
        NSString *text2 = [TBXML textForElement:bbf];
        if(text2 &&[text2 isEqualToString:@"false"]){
            
        }else{
            TBXMLElement *record0 = [TBXML childElementNamed:@"record" parentElement:bbf ];
            TBXMLElement *fat = [TBXML childElementNamed:@"value" parentElement:record0];
            NSString *str_fat = [TBXML textForElement:fat];
            
            TBXMLElement *bmi = [TBXML nextSiblingNamed:@"value" searchFromElement:fat];
            NSString *str_bmi = [TBXML textForElement:bmi];
            
            TBXMLElement *BasalMetaRate =[TBXML nextSiblingNamed:@"value" searchFromElement:bmi];
            NSString *str_BasalMetaRate = [TBXML textForElement:BasalMetaRate];
            
            dispatch_async(dispatch_get_main_queue(), ^{
               _bbf_fat.text = str_fat;
               _bbf_bmi.text = str_bmi;
               _bbf_BasalMetaRate.text = str_BasalMetaRate;
            });
        }
        
        //体温表
        TBXMLElement *temp = [TBXML childElementNamed:@"temp" parentElement:series];
        NSString *text3 = [TBXML textForElement:temp];
        if(text3 &&[text3 isEqualToString:@"false"]){
            
        }else{
            TBXMLElement *record0 = [TBXML childElementNamed:@"record" parentElement:temp ];
            TBXMLElement *temp = [TBXML childElementNamed:@"value" parentElement:record0];
            NSString *str_temp = [TBXML textForElement:temp];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [_tmp setText:str_temp];
            });
        }

        //血糖表
        TBXMLElement *bg = [TBXML childElementNamed:@"bg" parentElement:series];
        NSString *text4 = [TBXML textForElement:bg];
        if(text4 &&[text4 isEqualToString:@"false"]){
            
        }else{
            TBXMLElement *record0 = [TBXML childElementNamed:@"record" parentElement:bg ];
            TBXMLElement *bg = [TBXML childElementNamed:@"value" parentElement:record0];
            NSString *str_bg = [TBXML textForElement:bg];
            dispatch_async(dispatch_get_main_queue(), ^{
                _bg.text = str_bg;
            });
        }
        
        //血压表
        TBXMLElement *bp = [TBXML childElementNamed:@"bp" parentElement:series];
        NSString *text5 = [TBXML textForElement:bp];
        if(text5 &&[text5 isEqualToString:@"false"]){
            
        }else{
            TBXMLElement *record0 = [TBXML childElementNamed:@"record" parentElement:bp ];
            TBXMLElement *sbp = [TBXML childElementNamed:@"value" parentElement:record0];
            NSString *str_sbp = [TBXML textForElement:sbp];
            TBXMLElement *dbp = [TBXML nextSiblingNamed:@"value" searchFromElement:sbp];
            NSString *str_dbp = [TBXML textForElement:dbp];
            dispatch_async(dispatch_get_main_queue(), ^{
                _bp_sbp.text = str_sbp;
                 _bp_dbp.text = str_dbp;
            });

        }
        //血氧表
        TBXMLElement *po = [TBXML childElementNamed:@"po" parentElement:series];
        NSString *text6 = [TBXML textForElement:po];
        if(text6 &&[text6 isEqualToString:@"false"]){
            
        }else{
            TBXMLElement *record0 = [TBXML childElementNamed:@"record" parentElement:po ];
            TBXMLElement *spo2 = [TBXML childElementNamed:@"value" parentElement:record0];
            NSString *str_spo2 = [TBXML textForElement:spo2];
            dispatch_async(dispatch_get_main_queue(), ^{
                _po_spo2.text = str_spo2;
            });
        }
        
        //心电表
        TBXMLElement *ecg = [TBXML childElementNamed:@"ecg" parentElement:series];
        NSString *text7 = [TBXML textForElement:ecg];
        if(text7 &&[text7 isEqualToString:@"false"]){
            
        }else{
            TBXMLElement *record0 = [TBXML childElementNamed:@"record" parentElement:ecg ];
            TBXMLElement *ecg = [TBXML childElementNamed:@"value" parentElement:record0];
            NSString *str_ecg = [TBXML textForElement:ecg];
            dispatch_async(dispatch_get_main_queue(), ^{
                _ecg_hr.text = str_ecg;
            });
        }
        //肺活量表
        TBXMLElement *pf = [TBXML childElementNamed:@"pf" parentElement:series];
        NSString *text8 = [TBXML textForElement:pf];
        if(text8 &&[text8 isEqualToString:@"false"]){
            
        }else{
            TBXMLElement *record0 = [TBXML childElementNamed:@"record" parentElement:pf ];
            TBXMLElement *fvc = [TBXML childElementNamed:@"value" parentElement:record0];
            NSString *str_fvc = [TBXML textForElement:fvc];
            TBXMLElement *fev1 = [TBXML nextSiblingNamed:@"value" searchFromElement:fvc];
            NSString *str_fev1 = [TBXML textForElement:fev1];
            TBXMLElement *pef =[TBXML nextSiblingNamed:@"value" searchFromElement:fev1];
            NSString *str_pef = [TBXML textForElement:pef];
            
            TBXMLElement *fef25 =[TBXML nextSiblingNamed:@"value" searchFromElement:pef];
            NSString *str_fef25 = [TBXML textForElement:fef25];
            TBXMLElement *fef75 =[TBXML nextSiblingNamed:@"value" searchFromElement:fef25];
            NSString *str_fef75 = [TBXML textForElement:fef75];
            TBXMLElement *fef2575 =[TBXML nextSiblingNamed:@"value" searchFromElement:fef75];
            NSString *str_fef2575 = [TBXML textForElement:fef2575];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                _pf_fvc.text = str_fvc;
                _pf_fev1.text = str_fev1;
                _pf_pef.text = str_pef;
            });

        }

        //尿常规表
        TBXMLElement *pw = [TBXML childElementNamed:@"pw" parentElement:series];
        NSString *text9 = [TBXML textForElement:pw];
        if(text9 &&[text9 isEqualToString:@"false"]){
            
        }else{
            TBXMLElement *record0 = [TBXML childElementNamed:@"record" parentElement:pw ];
            TBXMLElement *uro = [TBXML childElementNamed:@"value" parentElement:record0];
            NSString *str_uro = [TBXML textForElement:uro];
            TBXMLElement *pro = [TBXML nextSiblingNamed:@"value" searchFromElement:uro];
            NSString *str_pro = [TBXML textForElement:pro];
            TBXMLElement *glu =[TBXML nextSiblingNamed:@"value" searchFromElement:pro];
            NSString *str_glu = [TBXML textForElement:glu];
            
            TBXMLElement *ket =[TBXML nextSiblingNamed:@"value" searchFromElement:glu];
            NSString *str_ket = [TBXML textForElement:ket];
            TBXMLElement *bil =[TBXML nextSiblingNamed:@"value" searchFromElement:ket];
            NSString *str_bil = [TBXML textForElement:bil];
            TBXMLElement *bld =[TBXML nextSiblingNamed:@"value" searchFromElement:bil];
            NSString *str_bld = [TBXML textForElement:bld];
            
            TBXMLElement *vc =[TBXML nextSiblingNamed:@"value" searchFromElement:bld];
            NSString *str_vc = [TBXML textForElement:vc];
            
            TBXMLElement *sg =[TBXML nextSiblingNamed:@"value" searchFromElement:vc];
            NSString *str_sg = [TBXML textForElement:sg];
            
            TBXMLElement *leu =[TBXML nextSiblingNamed:@"value" searchFromElement:sg];
            NSString *str_leu = [TBXML textForElement:leu];
            
            TBXMLElement *nit =[TBXML nextSiblingNamed:@"value" searchFromElement:leu];
            NSString *str_nit = [TBXML textForElement:nit];
            
            TBXMLElement *ph =[TBXML nextSiblingNamed:@"value" searchFromElement:nit];
            NSString *str_ph = [TBXML textForElement:ph];
            dispatch_async(dispatch_get_main_queue(), ^{
                _pw_bil.text = str_bil;
                _pw_bld.text = str_bld;
                _pw_glu.text = str_glu;
                _pw_ket.text = str_ket;
                _pw_leu.text = str_leu;
                _pw_nit.text = str_nit;
                _pw_ph.text = str_ph;
                _pw_pro.text = str_pro;
                _pw_sg.text = str_sg;
                _pw_uro.text = str_uro;
                _pw_vc.text = str_vc;
            });

        }

        /*
        TBXMLElement *author = [TBXML childElementNamed:@"author" parentElement:root];
        NSString *name = [TBXML valueOfAttributeNamed:@"name" forElement:author];
        NSLog(@"author:%@", name);
        TBXMLElement *book = [TBXML childElementNamed:@"book" parentElement:author];
        TBXMLElement *descriptionElem = [TBXML childElementNamed:@"description" parentElement:book];
        NSString * description = [TBXML textForElement:descriptionElem];
        NSLog(@"author:%@", description);
         */
    } failure:^(TBXML *tbxml, NSError *error) {
        debugLog(@"获取数据失败~");
    }];
}

-(void)rightItemClick:(id)sender
{
    HealthAddViewController *addView = [HealthAddViewController new];
    addView.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:addView animated:YES];
}
- (IBAction)filterName:(id)sender {
    [_textField1 becomeFirstResponder];
}

- (IBAction)filterDate:(id)sender {
    [_textField becomeFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark ----------关于性别选择---------------
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [[_nos objectAtIndex:row]objectForKey:@"name"];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    debugLog(@"count:%d",_nos.count);
    return _nos.count;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    debugLog(@"选择的性别是：%@",[_nos objectAtIndex:row]);
    
    NSDictionary *no = [_nos objectAtIndex:row];
    _nameLabel.text = [no objectForKey:@"name"];
    [self getXMLDATA:[no objectForKey:@"number"]];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
